﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lucene.Net.Index;

namespace Lucandra.Net
{
    internal sealed class LucandraTermPositions : LucandraTermDocs, TermPositions
    {
        private int termPosition;
        private int[] termPositions;

        public LucandraTermPositions(LucandraReader p)
            : base(p)
        {
            this.termPosition = 0;
            this.termPositions = null;
        }

        public int NextPosition()
        {
            if (this.termDocuments == null || this.termDocuments.Length == 0)
                return -1;

            if (this.termPositions == null)
                this.termPositions = base.termDocuments[base.documentPosition].Positions.ToArray();

            if (this.termPositions.Length == 0)
                return -1;

            int pos = this.termPositions[this.termPosition];
            this.termPosition++;

            return pos;
        }

        public int GetPayloadLength()
        {
            return 0;
        }

        public byte[] GetPayload(byte[] data, int offset)
        {
            return null;
        }

        public bool IsPayloadAvailable()
        {
            return false;
        }

        protected override void OnDocumentPositionChanged()
        {
            this.termPosition = 0;
            this.termPositions = null;
        }
    }
}
